package leo.util
{
	import flash.geom.Point;
	import flash.utils.ByteArray;
	
	import leo.data.GameConst;

	/**
	 * 游戏中用到的工具类 
	 * @author leo
	 * 
	 */	
	public class GameUtil
	{
		private static var _instance :GameUtil= null;
			
		public function GameUtil()
		{
		}
		
		
		public static function get instance() :GameUtil
		{
			if(_instance == null)
			{
				_instance = new GameUtil();
			}
			return _instance;
		}
		/**
		 * 判断两数组是否相等 
		 * @param ary1
		 * @param ary2
		 * @return 
		 * 
		 */		
		public function aryIsEquation(ary1 :Array,ary2 :Array):Boolean
		{
			if (ary1.length != ary2.length)
			{
				return false;
			}
			var len:Number = ary1.length;
			for (var i:Number = 0; i < len; i++) 
			{
				if (ary1[i] != ary2[i]) 
				{
					return false;
				}
			}
			return true;
		}
		/**
		 * 数组复制 
		 * @param ary
		 * @return 
		 * 
		 */		
		public function copyAry(ary :Array):Array
		{
			if(!ary) trace("copyAry result is null");
			var result :Array;
			var byteAry :ByteArray = new ByteArray();
			byteAry.writeObject(ary);
			byteAry.position = 0;
			result = byteAry.readObject() as Array;
			return result;
		}
		/**
		 * 索引转地图上的像素点 
		 * @param point
		 * @return 
		 * 
		 */		
		public function indexToPixel(point :*):Point
		{
			if(!point) 
			{
				trace("indexToPixel result is null");
				return null;
			}
			var p :Point = new Point();
			p.x = point.x * GameConst.TILE_WIDTH;
			p.y = point.y * GameConst.TILE_HEIGHT;
			
			return p;
		}

	}
}